package com.wfm;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) {
        add();
    }

    static Cache<String, Object> cache = Caffeine.newBuilder()
            .expireAfterWrite(10, TimeUnit.MINUTES)
            .maximumSize(10_000)
            .build();

    // caffeine 添加缓存
    public static void add() {
        cache.put("key", "value");
        Object key = cache.getIfPresent("key");
        System.out.println("存在："+key);
        cache.invalidate("key");
        System.out.println("不存在："+cache.getIfPresent("key"));
        cache.get("key", k -> "value1");
        System.out.println("不存在则方法构造："+cache.getIfPresent("key"));
    }
}
